home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / pmake / lst / lstNext.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-19  |  2.4 KB  |  89 lines

  1. /*-
  2.  * LstNext.c --
  3.  *    Return the next node for a list.
  4.  *    The sequential functions access the list in a slightly different way.
  5.  *    CurPtr points to their idea of the current node in the list and they
  6.  *    access the list based on it. Because the list is circular, Lst_Next
  7.  *    and Lst_Prev will go around the list forever. Lst_IsAtEnd must be
  8.  *    used to determine when to stop.
  9.  *
  10.  * Copyright (c) 1988 by University of California Regents
  11.  *
  12.  * Permission to use, copy, modify, and distribute this
  13.  * software and its documentation for any purpose and without
  14.  * fee is hereby granted, provided that the above copyright
  15.  * notice appears in all copies.  Neither the University of California nor
  16.  * Adam de Boor makes any representations about the suitability of this
  17.  * software for any purpose.  It is provided "as is" without
  18.  * express or implied warranty.
  19.  */
  20. #ifndef lint
  21. static char *rcsid =
  22. "$Id: lstNext.c,v 1.8 88/11/17 20:53:40 adam Exp $ SPRITE (Berkeley)";
  23. #endif lint
  24.  
  25. #include    "lstInt.h"
  26.  
  27. /*-
  28.  *-----------------------------------------------------------------------
  29.  * Lst_Next --
  30.  *    Return the next node for the given list.
  31.  *
  32.  * Results:
  33.  *    The next node or NILLNODE if the list has yet to be opened. Also
  34.  *    if the list is non-circular and the end has been reached, NILLNODE
  35.  *    is returned.
  36.  *
  37.  * Side Effects:
  38.  *    the curPtr field is updated.
  39.  *
  40.  *-----------------------------------------------------------------------
  41.  */
  42. LstNode
  43. Lst_Next (l)
  44.     Lst              l;
  45. {
  46.     register ListNode    tln;
  47.     register List     list = (List)l;
  48.     
  49.     if ((LstValid (l) == FALSE) ||
  50.     (list->isOpen == FALSE)) {
  51.         return (NILLNODE);
  52.     }
  53.     
  54.     list->prevPtr = list->curPtr;
  55.     
  56.     if (list->curPtr == NilListNode) {
  57.     if (list->atEnd == Unknown) {
  58.         /*
  59.          * If we're just starting out, atEnd will be Unknown.
  60.          * Then we want to start this thing off in the right
  61.          * direction -- at the start with atEnd being Middle.
  62.          */
  63.         list->curPtr = tln = list->firstPtr;
  64.         list->atEnd = Middle;
  65.     } else {
  66.         tln = NilListNode;
  67.         list->atEnd = Tail;
  68.     }
  69.     } else {
  70.     tln = list->curPtr->nextPtr;
  71.     list->curPtr = tln;
  72.  
  73.     if (tln == list->firstPtr || tln == NilListNode) {
  74.         /*
  75.          * If back at the front, then we've hit the end...
  76.          */
  77.         list->atEnd = Tail;
  78.     } else {
  79.         /*
  80.          * Reset to Middle if gone past first.
  81.          */
  82.         list->atEnd = Middle;
  83.     }
  84.     }
  85.     
  86.     return ((LstNode)tln);
  87. }
  88.  
  89.